package com.isunny.mode.tactics;

import com.isunny.mode.tactics.factory.EvictionStrategyLoopFactory;
import com.isunny.mode.tactics.factory.EvictionStrategyPrototypeFactory;
import com.isunny.mode.tactics.factory.EvictionStrategySingleFactory;
import com.isunny.mode.tactics.strategy.EvictionStrategy;

import java.lang.reflect.InvocationTargetException;

/**
 * 策略模式
 * @author luom
 * @date 2022/2/25
 */
public class Test {
    public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {

        // 单例工厂
        EvictionStrategy evictionStrategy = EvictionStrategySingleFactory.getEvictionType(EvictionType.LFU);
        evictionStrategy.evictionCache();

        // 配置工厂
        EvictionStrategy evictionStrategy1 = EvictionStrategyPrototypeFactory.getEvictionStrategy(EvictionType.FIFO);
        evictionStrategy1.evictionCache();

        // 配置工厂优化
        EvictionStrategy evictionStrategy2 = EvictionStrategyLoopFactory.clientSelect("LRU");
        evictionStrategy2.evictionCache();

    }
}
